package controllers

import (
	"encoding/xml"
	"github.com/astaxie/beego"
)

type GoodsController struct {
	beego.Controller
}

func (c *GoodsController) Get() {

	c.TplName = "goods.tpl"
}

type Product struct {
	Title   string `json:"title" xml:"title"`
	Content string `json:"content" xml:"content"`
}

//接收Post传过来的XML数据
//注意：在配置文件里设置 copyrequestbody = true  改完配置要重新运行项目
func (c *GoodsController) Xml() {
	P := Product{}
	//str := string(c.Ctx.Input.RequestBody)
	//fmt.Println(str)
	var err error
	if err = xml.Unmarshal(c.Ctx.Input.RequestBody, &P); err == nil {
		c.Data["json"] = P
	} else {
		c.Data["json"] = err.Error()
	}
	c.ServeJSON()
}

func (c *GoodsController) RController() {
	cms := c.Ctx.Input.Param(":id")
	c.Ctx.WriteString("动态路由----" + cms)

}
